import moment from "moment";
import util from "../../utils/apl-common"
Component({
  options: {
    addGlobalClass: true
  },
  externalClasses:['cutom-class'],
  /**
   * 组件的属性列表
   */
  properties: {
    orderData: {
      type: Object,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    /**订单渲染数据 */
    orderDataAppointment: {},
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDetail(e) {
      let orderDataset = e.currentTarget.dataset.order
      var myEventDetail = {
        orderDataset
      }
      var myEventOption = {}
      this.triggerEvent('orderDetail', myEventDetail, myEventOption)
    },
    onApply(e) {
      let orderDataset = e.currentTarget.dataset.order
      var myEventDetail = {
        orderDataset
      }
      var myEventOption = {}
      this.triggerEvent('orderApply', myEventDetail, myEventOption)
    },
    /**
     * 设置订单数据
     * @param {*} item 订单数据源
     */
    setOrderData(item) {
      let orderDataAppointment= {};
      orderDataAppointment.id = item.id;
      if (item.serviceCategory == "YS") {
        orderDataAppointment.title = `${item.serviceCategory_dictText} | ${item.serviceRank_dictText} ${item.serviceDays}${item.serviceUnit_dictText}`;
      } else {
        orderDataAppointment.title = `${item.serviceCategory_dictText} ${item.serviceDays}${item.serviceUnit_dictText}`;
      }
      orderDataAppointment.status = item.status;
      orderDataAppointment.address = item.address;
      orderDataAppointment.planStartDate = moment(item.planStartDate).format("YYYY-MM-DD");
      orderDataAppointment.adviserName = item.adviserName;
      orderDataAppointment.adviserTel = item.adviserTel;
      orderDataAppointment.registrationStartTime = moment(util.insertStr(item.registrationStartTime,8,"")).format("YYYY-MM-DD hh:mm:ss");
      orderDataAppointment.registrationEndTime = moment(util.insertStr(item.registrationEndTime,8,"")).format("YYYY-MM-DD hh:mm:ss");
      this.setData({
        orderDataAppointment,
      });
    },
  },

  /**
   * 组件生命周期
   */
  lifetimes: {
    attached() {
      this.setOrderData(this.data.orderData);
    },
  },
});
